package com.camemax.rabbitmq.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitMQUtils {
    private static final ConnectionFactory connectionFactory = new ConnectionFactory();

    static {
        connectionFactory.setHost("172.16.205.100");
        connectionFactory.setVirtualHost("/");
        connectionFactory.setPort(25672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
    }

    public static ConnectionFactory createFactory(){
        return connectionFactory;
    }

    public static void close(Channel channel, Connection connection){
        if ( channel != null && channel.isOpen()){
            try {
                channel.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if ( connection != null && connection.isOpen()){
            try {
                connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
